//package com.aabbc.database.config;
//
//import com.aabbc.database.bean.MultiRoutingDataSource;
//import com.aabbc.database.enums.DBTypeEnum;
//import com.baomidou.mybatisplus.annotation.DbType;
//import com.baomidou.mybatisplus.core.MybatisConfiguration;
//import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
//import com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean;
//import org.apache.ibatis.session.SqlSessionFactory;
//import org.apache.ibatis.type.JdbcType;
//import org.mybatis.spring.annotation.MapperScan;
//import org.springframework.beans.factory.annotation.Qualifier;
//import org.springframework.boot.context.properties.ConfigurationProperties;
//import org.springframework.boot.jdbc.DataSourceBuilder;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.context.annotation.Primary;
//import org.springframework.transaction.annotation.EnableTransactionManagement;
//
//import javax.sql.DataSource;
//import java.util.HashMap;
//import java.util.Map;
//
///**
// * DataSourceConfig
// *
// * @author: chenfenghai
// * @version: 1.0
// * @date: 2020-04-02 10:53
// * @blame Team
// */
//@Configuration
//@EnableTransactionManagement
//@MapperScan("com.aabbc.database.mapper")
//public class DataSourceConfig {
//
//    @Bean("masterDataSource")
//    @ConfigurationProperties("spring.datasource.master")
//    public DataSource masterDataSource() {
//        return DataSourceBuilder.create().build();
//    }
//
//    @Bean("slave1DataSource")
//    @ConfigurationProperties("spring.datasource.slave1")
//    public DataSource slave1DataSource() {
//        return DataSourceBuilder.create().build();
//    }
//
//    @Bean("slave2DataSource")
//    @ConfigurationProperties("spring.datasource.slave2")
//    public DataSource slave2DataSource() {
//        return DataSourceBuilder.create().build();
//    }
//
//    @Bean
//    @Primary
//    public DataSource multipleDataSource() {
//        Map<Object, Object> targetDataSources = new HashMap<>(8);
//        targetDataSources.put(DBTypeEnum.MASTER, masterDataSource());
//        targetDataSources.put(DBTypeEnum.SLAVE1, slave1DataSource());
//        targetDataSources.put(DBTypeEnum.SLAVE2, slave2DataSource());
//
//        MultiRoutingDataSource myRoutingDataSource = new MultiRoutingDataSource();
//        myRoutingDataSource.setDefaultTargetDataSource(masterDataSource());
//        myRoutingDataSource.setTargetDataSources(targetDataSources);
//        return myRoutingDataSource;
//    }
//
//    @Bean("sqlSessionFactory")
//    public SqlSessionFactory sqlSessionFactory() throws Exception {
//        MybatisConfiguration configuration = new MybatisConfiguration();
//        configuration.setJdbcTypeForNull(JdbcType.NULL);
//        configuration.setMapUnderscoreToCamelCase(true);
//        configuration.setCacheEnabled(false);
//
//        MybatisSqlSessionFactoryBean sqlSessionFactory = new MybatisSqlSessionFactoryBean();
//        sqlSessionFactory.setDataSource(multipleDataSource());
//        sqlSessionFactory.setConfiguration(configuration);
//        sqlSessionFactory.setPlugins(paginationInterceptor());
//        return sqlSessionFactory.getObject();
//    }
//
//    /*@Bean
//    public GlobalConfiguration globalConfiguration() {
//        GlobalConfiguration conf = new GlobalConfiguration(new LogicSqlInjector());
//        conf.setLogicDeleteValue("-1");
//        conf.setLogicNotDeleteValue("1");
//        conf.setIdType(0);
//        //conf.setMetaObjectHandler(new MyMetaObjectHandler());
//        conf.setDbColumnUnderline(true);
//        conf.setRefresh(true);
//        return conf;
//    }*/
//
//    /**
//     ** mybatis-plus分页插件
//     * @return PaginationInterceptor
//     */
//    @Bean
//    public PaginationInterceptor paginationInterceptor() {
//        PaginationInterceptor interceptor = new PaginationInterceptor();
//        // 设置数据库类型，参考DbType枚举
//        interceptor.setDialectType(DbType.MYSQL.getDb());
//        // 设置请求的页面大于最大页后操作， true调回到首页，false 继续请求  默认false
//        interceptor.setOverflow(false);
//        // 设置最大单页限制数量，默认 500 条，-1 不受限制
//        interceptor.setLimit(10000);
//        return interceptor;
//    }
//}
